package com.tinyseed.emcp.api.basicdata.rest;

import com.tinyseed.emcp.api.basicdata.model.MonitorInputDTO;
import com.tinyseed.emcp.api.basicdata.service.MonitorService;
import com.tinyseed.hmxx.common.base.BaseController;
import com.tinyseed.hmxx.common.base.PageData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/***
 * @ClassName: MonitorController
 * @Description: TODO
 * @Auther: Harlan.Xiong
 * @Date: 2019-11-24 20:36
 * @version : V1.0
 */
@Slf4j
@RestController
@RequestMapping("/monitor")
@Api("监控点管理接口")
public class MonitorController extends BaseController {

    @Autowired
    private MonitorService monitorService;

    @GetMapping(value = "list")
    @ApiOperation("分页查询")
    public ResponseEntity list(MonitorInputDTO monitorInputDTO, int limit, int page) {
        PageData pageData = monitorService.findAll(monitorInputDTO, page, limit);
        return new ResponseEntity<>(pageData, HttpStatus.OK);

    }

    @GetMapping(value = "/get")
    @ApiOperation("获取详情")
    public ResponseEntity get(@RequestParam(value = "monitorId", required = true) Long monitorId) {
        return new ResponseEntity<>(monitorService.findById(monitorId), HttpStatus.OK);

    }

    @PostMapping(value = "delete")
    @ApiOperation("删除")
    public ResponseEntity delete(@RequestParam(value = "monitorId", required = true) Long monitorId) {
        monitorService.deleteById(monitorId);
        return new ResponseEntity<>(HttpStatus.OK);

    }

    @PostMapping(value = "save")
    @ApiOperation("保存")
    public ResponseEntity save(@RequestBody MonitorInputDTO monitorInputDTO) {
        return new ResponseEntity<>(monitorService.save(monitorInputDTO), HttpStatus.OK);

    }

    @GetMapping(value = "/getTree")
    @ApiOperation("获取企业车间树")
    public ResponseEntity getTree() {
        return new ResponseEntity<>(monitorService.getTree(), HttpStatus.OK);

    }

}
